<html>
    <head>
        <title>LCD Search Page</title>
        <script type="text/javascript" language="javascript">
            function saveContractorType()
            {
                document.getElementById('hiddenContractorTypeId').value = document.getElementById('contractorType').value;
            }
            function saveStateAndTitle()
            {
                document.getElementById('hiddenStateId').value = document.getElementById('stateId').value;
                document.getElementById('hiddenTitle').value = document.getElementById('title').value;
            }
            function saveTitleAndContractorIds()
            {
                var selectedArray = new Array();
                var contractorIdsObj = document.getElementById('contractorNumbersAndNames');
                var i;
                var count = 0;
                for (i=0; i<contractorIdsObj.options.length; i++) {
                    if (contractorIdsObj.options[i].selected) {
                        selectedArray[count] = contractorIdsObj.options[i].value;
                        count++;
                    }
                }
                document.getElementById('hiddenTitle2').value = document.getElementById('title').value;
                document.getElementById('hiddenContractorTypeId2').value = document.getElementById('contractorType').value;
                document.getElementById('hiddenContractorIds2').value = selectedArray;
            }
            function saveStateAndContractorIds()
            {
                var selectedArray = new Array();
                var contractorIdsObj = document.getElementById('contractorNumbersAndNames');
                var i;
                var count = 0;
                for (i=0; i<contractorIdsObj.options.length; i++) {
                    if (contractorIdsObj.options[i].selected) {
                        selectedArray[count] = contractorIdsObj.options[i].value;
                        count++;
                    }
                }
                document.getElementById('hiddenState3').value = document.getElementById('stateId').value;
                document.getElementById('hiddenContractorTypeId3').value = document.getElementById('contractorType').value;
                document.getElementById('hiddenContractorIds3').value = selectedArray;
            }
            function saveStateAndTitleAndContractorIds()
            {
                var selectedArray = new Array();
                var contractorIdsObj = document.getElementById('contractorNumbersAndNames');
                var i;
                var count = 0;
                for (i=0; i<contractorIdsObj.options.length; i++) {
                    if (contractorIdsObj.options[i].selected) {
                        selectedArray[count] = contractorIdsObj.options[i].value;
                        count++;
                    }
                }
                document.getElementById('hiddenState4').value = document.getElementById('stateId').value;
                document.getElementById('hiddenTitle4').value = document.getElementById('title').value;
                document.getElementById('hiddenContractorTypeId4').value = document.getElementById('contractorType').value;
                document.getElementById('hiddenContractorIds4').value = selectedArray;
            }
        </script>
    </head>
    <body>
        <!-- Search Criteria Part -->
        <table border="0" width="100%" style="padding-left: 0px;">
            <tr align="center">
                <td style="font-weight: bold; font-size: 70px;" align="center" colspan="3">
                    <font color="000099">Soluble Systems, LLC</font>
                </td>
            </tr>
            <tr>
                <td>
                    <br>
                </td>
            </tr>
            <tr align="center">
                <td width="38%" align="right">
                    Select State :
                </td>
                <td width="20%" align="center">
                    <?php echo form_open('search/getLCDsByState'); ?>
                    <select id="stateId" name="stateId" style="width: 233px;">
                        <option value="">--- Select a State ---</option>
                        <?php
                        for ($i = 0; $i < count($stateDescription); $i++) {
                            if ($stateName == $stateDescription[$i])
                                echo '<option value="' . $stateId[$i] . '" selected>' . $stateDescription[$i] . '</option>';
                            else
                                echo '<option value="' . $stateId[$i] . '">' . $stateDescription[$i] . '</option>';
                        }
                        ?>
                    </select>
                </td>
                <td width="42%" align="left">
                    <input type="submit" name="submit"  value="Search LCD by state" />
                    <?php echo form_close(); ?>
                    </td>
                </tr>
                <tr align="center">
                    <td width="38%" align="right">
                        Enter Title Keywords :
                    </td>
                    <td width="20%" align="center">
                    <?php echo form_open('search/getLCDsByTitle'); ?>
                        <input id="title" name="title" type="text" style="width: 233px;" <?php
                        if ($title != '') {
                            echo 'value="' . $title . '"';
                        }
                    ?> />
                </td>
                <td width="42%" align="left">
                    <input type="submit" name="submit" value="Search LCD by Title Keyword" />
                    <?php echo form_close(); ?>

                    </td>
                </tr>

                <tr align="center">
                    <td width="38%" align="right">
                        Select Contractor Type :
                    </td>
                    <td width="20%" align="center">
                    <?php echo form_open('search/getContractorsByContractorType'); ?>
                        <select id="contractorType" name="contractorType" style="width: 233px;">
                            <option value="">--- Select a Contractor Type ---</option>
                        <?php
                        for ($i = 0; $i < count($contractorTypeId); $i++) {
                            if ($contractorTypeIdSelected == $contractorTypeId[$i])
                                echo '<option value=' . $contractorTypeId[$i] . ' selected>' . $contractorTypeDescription[$i] . '</option>';
                            else
                                echo '<option value=' . $contractorTypeId[$i] . '>' . $contractorTypeDescription[$i] . '</option>';
                        }
                        ?>
                    </select>
                </td>
                <td width="42%" align="left">
                    <input type="submit" name="submit"  value="Get Related Contractors" />
                    <?php echo form_close(); ?>
                    </td>
                </tr>
            <?php if (count($contractorId) > 0) {
            ?>
                            <tr align="center">
                                <td width="38%" align="right">
                                    Select Contractor :
                                </td>
                                <td width="20%" align="center">
                    <?php echo form_open('search/getLCDsByContractorId'); ?>
                            <select id="contractorNumbersAndNames" name="contractorNumbersAndNames[]" style="width: 233px;" size="10" multiple>
                                <option value="0">--- Select a Contractor ---</option>
                        <?php
                            for ($i = 0; $i < count($contractorId); $i++) {
                                if ($contractorIdList != '' && in_array($contractorId[$i], $contractorIdList))
                                    echo '<option value="' . $contractorId[$i] . '" title="' . $contractorNameList[$i] . '" selected>' . $contractorNumber[$i] . ' => ' . $contractorNameList[$i] . '</option>';
                                else
                                    echo '<option value="' . $contractorId[$i] . '" title="' . $contractorNameList[$i] . '">' . $contractorNumber[$i] . ' => ' . $contractorNameList[$i] . '</option>';
                            }
                        ?>
                        </select>
                        <input type="hidden" id="hiddenContractorTypeId" name="hiddenContractorTypeId" value="" />
                    </td>
                    <td width="42%" align="left">
                        <input type="submit" name="submit"  value="Search LCD By Contractors" onClick="javascript: saveContractorType();" />
                    <?php echo form_close(); ?>
                        </td>
                    </tr>
            <?php } ?>
                        <tr>
                            <td colspan="3" align="center">
                                <table border="0" width="50%">
                                    <tr>
                                        <td>
                                <?php echo form_open('search/getLCDsByStateAndTitle'); ?>
                                <input type="hidden" id="hiddenStateId" name="hiddenStateId" value="" />
                                <input type="hidden" id="hiddenTitle" name="hiddenTitle" value="" />
                                <input type="submit" name="submit"  value="Refine Search by State and Title" onClick="javascript: saveStateAndTitle();" />
                                <?php echo form_close(); ?>
                            </td>
                            <td>
                                <?php echo form_open('search/getLCDsByTitleAndContractorId'); ?>
                                <input type="hidden" id="hiddenTitle2" name="hiddenTitle2" value="" />
                                <input type="hidden" id="hiddenContractorTypeId2" name="hiddenContractorTypeId2" value="" />
                                <input type="hidden" id="hiddenContractorIds2" name="hiddenContractorIds2[]" value="" />
                                <input type="submit" name="submit"  value="Refine Search by Contractor and Title" onClick="javascript: saveTitleAndContractorIds();" />
                                <?php echo form_close(); ?>
                            </td>
                            <td>
                                <?php echo form_open('search/getLCDsByStateAndContractorId'); ?>
                                <input type="hidden" id="hiddenState3" name="hiddenState3" value="" />
                                <input type="hidden" id="hiddenContractorTypeId3" name="hiddenContractorTypeId3" value="" />
                                <input type="hidden" id="hiddenContractorIds3" name="hiddenContractorIds3[]" value="" />
                                <input type="submit" name="submit"  value="Refine Search by State and Contractor" onClick="javascript: saveStateAndContractorIds();" />
                                <?php echo form_close(); ?>
                            </td>
                            <td>
                                <?php echo form_open('search/getLCDsByStateAndTitleAndContractorId'); ?>
                                <input type="hidden" id="hiddenState4" name="hiddenState4" value="" />
                                <input type="hidden" id="hiddenTitle4" name="hiddenTitle4" value="" />
                                <input type="hidden" id="hiddenContractorTypeId4" name="hiddenContractorTypeId4" value="" />
                                <input type="hidden" id="hiddenContractorIds4" name="hiddenContractorIds4[]" value="" />
                                <input type="submit" name="submit"  value="Refine Search by All Three" onClick="javascript: saveStateAndTitleAndContractorIds();" />
                                <?php echo form_close(); ?>
                            </td>
                        </tr>
                    </table>






                </td>
            </tr>
        </table>


        <!-- Search Result Listing Part -->
        <br><br>
        <?php
                                if ($stateName != '' || $title != '' || $contractorIdList != '') {
                                    $rowCount = 0;
                                    if (count($lcdId) > 0) {
                                        $duplicateLCDid = array();
                                        for ($i = 0; $i < count($lcdId); $i++) {
                                            if (!in_array($lcdId[$i], $duplicateLCDid)) {
                                                $duplicateLCDid[] = $lcdId[$i];
                                                $rowCount++;
                                            }
                                        }
                                    }
        ?>
                                    <table datapagesize="10" width="95%" align="center">
            <?php if ($stateName != '') {
 ?>
                                        <tr>
                                            <td bgcolor="0000FF" style="font-weight: bold; font-size: 25px;" align="left" colspan="3">
                                                <font color="white"># LCDs: <?php echo $rowCount; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
                                                <font color="white"><?php echo $stateName; ?> State</font>
                                            </td>
                                        </tr>
            <?php } ?>
<?php if ($title != '') { ?>
                                        <tr>
                                            <td bgcolor="0000FF" style="font-weight: bold; font-size: 25px;" align="left" colspan="3">
                                                <font color="white"># LCDs: <?php echo $rowCount; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
                                                <font color="white"><?php echo $title; ?> Keyword</font>
                                            </td>
                                        </tr>
            <?php } ?>
<?php if ($contractorIdList != '') { ?>
                                        <tr>
                                            <td bgcolor="0000FF" style="font-weight: bold; font-size: 25px;" align="left" colspan="3">
                                                <font color="white"># LCDs: <?php echo $rowCount; ?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
                                                <font color="white">LCDs for Selected Contractors</font>
                                            </td>
                                        </tr>
<?php } ?>
                                    <tr bgcolor="3366FF" style="font-weight: bold">
                                        <td width="10%" style="padding-left: 2px;">
                                            <font color="white">LCD ID</font>
                                        </td>
                                        <td width="60%" style="padding-left: 2px;">
                                            <font color="white">LCD TITLE</font>
                                        </td>
                                        <td width="30%" style="padding-left: 2px; ">
                                            <font color="white">CONTRACTOR NAME</font>
                                        </td>
                                    </tr>
            <?php
                                    if (count($lcdId) > 0) {
                                        $duplicateLCDid = array();
                                        $rowCount = 0;
                                        for ($i = 0; $i < count($lcdId); $i++) {
                                            if (!in_array($lcdId[$i], $duplicateLCDid)) {
                                                if ($rowCount % 2 != 0) {
                                                    echo "<tr bgcolor='99CCFF'>";
                                                } else {
                                                    echo "<tr>";
                                                }
                                                echo "<td width='10%' style='padding: 1px 0 1px 2px;'><a href='showLCDInformation/" . $lcdId[$i] . "' target='_blank'>" . $lcdId[$i] . "<a></td>";
                                                $lcdTitle[$i] = str_replace("</b>", "", (str_replace("<b>", "", $lcdTitle[$i])));
                                                echo "<td width='60%' style='font-weight: normal; padding: 1px 0 1px 2px; text-transform: uppercase;'>" . $lcdTitle[$i] . "</td>";
                                                echo "<td width='30%' style='padding: 1px 0 1px 2px; text-transform: uppercase;'>" . $contractorName[$i] . "</td>";
                                                echo "</tr>";
                                                $duplicateLCDid[] = $lcdId[$i];
                                                $rowCount++;
                                            }
                                        }
                                    } else {
            ?>

                                        <tr>
                                            <td style="font-weight: bold; font-size: 100px;" align="center" colspan="3">
                                                NO LCDs
                                            </td>
                                        </tr>
            <?php
                                    }
            ?>
                                </table>
        <?php
                                }
        ?>

    </body>
</html>